package com.sample.wechat;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.sword.wechat4j.WechatSupport;
import org.sword.wechat4j.response.ArticleResponse;
import org.sword.wechat4j.response.MusicResponse;
import org.sword.wechat4j.response.VideoResponse;


/**
 * 微信服务桩
 * @author ChengNing
 * @date   2015年1月7日
 */
public class MyWechat extends WechatSupport {
	
	private static Logger logger = Logger.getLogger(MyWechat.class);

	public MyWechat(HttpServletRequest request) {
		super(request);
	}

	/**
	 * 文本消息
	 */
	@Override
	protected void onText() {
	    responseCustomerService();
	}
	/**
	 * 图片消息
	 */
	@Override
	protected void onImage() {
	    responseCustomerService();
	}

	/**
	 * 语音消息
	 */
	@Override
	protected void onVoice() {
	    responseCustomerService();
	}

	/**
	 * 视频消息
	 */
	@Override
	protected void onVideo() {
	    responseCustomerService();
	}
	
	/**
	 * 地理位置消息
	 */
	@Override
	protected void onLocation() {
	    responseCustomerService();
	}
	/**
	 * 链接消息
	 */
	@Override
	protected void onLink() {
	    responseCustomerService();
	}
	
	
	/**
	 * 未知消息类型，错误处理
	 */
	@Override
	protected void onUnknown() {
	    responseCustomerService();

	}

	/**
	 * 扫描二维码事件
	 */
	@Override
	protected void scan() {
	    responseCustomerService();
	}

	/**
	 * 订阅事件
	 */
	@Override
	protected void subscribe() {
		String FromUserName = wechatRequest.getFromUserName();
		//用户未关注时扫描二维码事件,会多一个EventKey和Ticket节点
		String Ticket = wechatRequest.getTicket();

		String result = "订阅事件FromUserName:" + FromUserName;
		if(StringUtils.isNotBlank(Ticket)){
			result = "扫描带场景值二维码事件FromUserName:" + FromUserName + ", Ticket:" + Ticket;
		}
		logger.info(result);
		responseText(result);
	}
	
	/**
	 * 取消订阅事件
	 */
	@Override
	protected void unSubscribe() {
		String FromUserName = wechatRequest.getFromUserName();
		String result = "取消订阅事件FromUserName:" + FromUserName;
		logger.info(result);
		responseText(result);
	}
	
	/**
	 * 点击菜单跳转链接时的事件推送
	 */
	@Override
	protected void view() {
		String link = super.wechatRequest.getEventKey();
		logger.info("点击菜单跳转链接时的事件推送link:" + link);
		responseText("点击菜单跳转链接时的事件推送link:" + link);
	}

	/**
	 * 自定义菜单事件
	 */
	@Override
	protected void click() {
		String key = super.wechatRequest.getEventKey();
		logger.info("自定义菜单事件eventKey:" + key);
		responseText("自定义菜单事件eventKey:" + key);
	}
	
	/**
	 * 上报地理位置事件
	 */
	@Override
	protected void location() {
		String Latitude = wechatRequest.getLatitude();
		String Longitude = wechatRequest.getLongitude();
		String Precision = wechatRequest.getPrecision();
		String result = "上报地理位置事件Latitude:" + Latitude + ", Longitude:" + Longitude + ", Precision:" + Precision;
		logger.info(result);
		responseText(result);
	}
	
	/**
	 * 模板消息发送成功推送事件
	 */
	@Override
	protected void templateMsgCallback() {
		String MsgID = wechatRequest.getMsgId();
		String Status = wechatRequest.getStatus();
		String result = "模板消息发送成功推送事件MsgID:" + MsgID + ", Status:" + Status;
		logger.info(result);
	}
	/**
	 * 弹出地理位置选择器的事件
	 */
	@Override
	protected void locationSelect() {
		String Location_X = wechatRequest.getSendLocationInfo().getLocation_X();
		String Location_Y = wechatRequest.getSendLocationInfo().getLocation_Y();
		String Scale = wechatRequest.getSendLocationInfo().getScale();
		String Label = wechatRequest.getSendLocationInfo().getLabel();
		String Poiname = wechatRequest.getSendLocationInfo().getPoiname();
		String result = "弹出地理位置选择器的事件Location_X:" + Location_X + 
				", Location_Y:" + Location_Y+ 
				", Scale:" + Scale+ 
				", Label:" + Label+ 
				", Poiname:" + Poiname;
		logger.info(result);
		responseText(result);
	}
	/**
	 * 弹出拍照或者相册发图的事件
	 */
	@Override
	protected void picPhotoOrAlbum() {
		String Count = wechatRequest.getSendPicsInfo().getCount();
		String PicMd5Sum = "";
		if(StringUtils.isNotBlank(Count) && !Count.equals("0")){
			PicMd5Sum = wechatRequest.getSendPicsInfo().getItem().get(0).getPicMd5Sum();
		}
		String result = "弹出系统拍照发图的事件Count:" + Count + ", PicMd5Sum:" + PicMd5Sum;
		logger.info(result);
		responseText(result);
	}
	/**
	 * 弹出系统拍照发图的事件
	 */
	@Override
	protected void picSysPhoto() {
		String Count = wechatRequest.getSendPicsInfo().getCount();
		String result = "弹出系统拍照发图的事件Count:" + Count ;
		logger.info(result);
		responseText(result);
	}
	/**
	 * 弹出微信相册发图器的事件推送
	 */
	@Override
	protected void picWeixin() {
		String Count = wechatRequest.getSendPicsInfo().getCount();
		String result = "弹出系统拍照发图的事件Count:" + Count ;
		logger.info(result);
		responseText(result);
	}
	/**
	 * 扫码推事件
	 * 
	 */
	@Override
	protected void scanCodePush() {
		String ScanType = wechatRequest.getScanCodeInfo().getScanType();
		String ScanResult = wechatRequest.getScanCodeInfo().getScanResult();
		String result = "扫码推事件ScanType:" + ScanType + ", ScanResult:" + ScanResult;
		logger.info(result);
		responseText(result);
	}
	/**
	 * 扫码推事件且弹出“消息接收中”提示框的事件
	 */
	@Override
	protected void scanCodeWaitMsg() {
		String ScanType = wechatRequest.getScanCodeInfo().getScanType();
		String ScanResult = wechatRequest.getScanCodeInfo().getScanResult();
		String result = "扫码推事件ScanType:" + ScanType + ", ScanResult:" + ScanResult;
		logger.info(result);
		responseText(result);
	}

    @Override
    protected void kfCloseSession() {
        // TODO Auto-generated method stub
        
    }

    @Override
    protected void kfCreateSession() {
        // TODO Auto-generated method stub
        
    }

    @Override
    protected void kfSwitchSession() {
        // TODO Auto-generated method stub
        
    }

    @Override
    protected void onShortVideo() {
        // TODO Auto-generated method stub
        
    }
	



}
